package com.buddy.design.pattern._02singleton;

public class ThreadLocalSingleton {

    //注册式单例，在线程内部保证线程安全，伪线程安全的
    //多数据源切换
    private static final ThreadLocal<ThreadLocalSingleton> INSTANCE = new ThreadLocal<ThreadLocalSingleton>() {
        @Override
        protected ThreadLocalSingleton initialValue() {
            return new ThreadLocalSingleton();
        }
    };

    private ThreadLocalSingleton() {

    }

    public static ThreadLocalSingleton getInstance(){
        return INSTANCE.get();
    }

}
